/**
 * Created by zhangleilei on 2018/10/16.
 */
$(function () {
    var selectedTargetSegment=null;
    $("#groups-wrapper").find("li").click(function () {
        $(this).siblings("li").removeClass("active");
        $(this).addClass("active");

        $(".nav-ribbon-group").hide();
        var tabId=$(this).find("span").attr("data-switch-to")+"-group";
        $("#"+tabId).show();
    });
    $("#toggle_formatting_tag_display").click(function () {
        if ($("#editor-body").hasClass("ue-tag-show")){
            $("#editor-body").removeClass("ue-tag-show");
        }else {
            $("#editor-body").addClass("ue-tag-show");
        }
    });
    
    $("#clear_formatting_primary").click(function () {
         if (selectedTargetSegment==null){
             return;
         }
        clearTagPair(selectedTargetSegment);
    });

    $(".ue-target").find(".ue-segment").click(function () {
        selectedTargetSegment=$(this);
        $(".ue-target").find(".ue-segment").each(function (index,element) {
            $(element).removeClass("ue-row-active");
        });
        $(this).addClass("ue-row-active");

        var selectedIndex=$(this).attr("data-segment-index");
        $(".ue-gutter").find(".ue-cell").each(function (index,element) {
            $(element).removeClass("ue-row-active");
            if (index+1 ==selectedIndex){
                $(element).addClass("ue-row-active");
            }
        });
        $(".ue-source").find(".ue-segment").each(function (index,element) {
            $(element).removeClass("ue-row-active");
            if (index+1 ==selectedIndex){
                $(element).addClass("ue-row-active");
            }
        });
        $(".ue-status").find(".ue-cell").removeClass("ue-row-active");
        $("#status-id-"+selectedIndex).addClass("ue-row-active");
    });

});

function clearTagPair(obj) {
    obj.find("ue-inline-content").each(function () {
        clearTagPair($(this));
    });
    obj.find("ue-tagpair-content").each(function () {
        $(this).find("")
    });
}